import "./address.less";
import request from "../../../app/src/util/request";
import dialog from "../../util/dialog";
export default {
    template:`        
            <div class="plugin-box plugin-address">
                <div class="open-select form-group">
                    <label>是否开启插件</label><br />
                    <select class="form-control" v-model.number="open">
                        <option value="1">开启</option>
                        <option value="0">关闭</option>
                    </select>
                </div>
                
                <button type="button" class="btn btn-info" @click="submit">确认</button>
            </div>
            `,
    data(){
        return {
            open:0
        }
    },
    props:{
      api:{
          type:String
      }
    },
    computed:{
        data:function(){
            let data = {
                open:this.open
            }
            return data;
        }
    },
    created(){
        this.getSetting()
    },
    methods:{
        // Run
        /**
         * 获取参数
         */
        getSetting(){
            request("setting/easyFind",{
                return:["open"]
            },this.api)
                .then((res)=>{
                    if(res.data.status === "success"){
                        let data = res.data.data;
                        this.open = data.open;
                    }
                })
        },
        // Handel
        /**
         * 设置参数
         */
        submit(){
            request("setting/set",{
                data:this.data
            },this.api)
                .then((res)=>{
                    if(res.data.status === "success"){
                        dialog.alert(this,"设置成功");
                    }else{
                        dialog.alert(this,"设置失败");
                    }
                })
        }
    }
}